import re
# 四、常见匹配符
pattern = '\D'#匹配非数字的字符
# str = '9'
str = 'a'
print(re.match(pattern,str))
pattern1 = '\d'#匹配数字字符
str1 = '0'
print(re.match(pattern1,str1))
pattern2 = '\s'#匹配空格、\n、\t
# str2 = ' '
# str2 = '\n'
# str2 = '\t'
str2 = '_'
print(re.match(pattern2,str2))
pattern3 = '\w'#匹配字母、数字、下划线
# str3 = 'a'
# str3 = '3'
str3 = '_'
# str3 = 'W'
# str3 = '@'
print(re.match(pattern3,str3))
pattern4 = '\W'#非字母数字下划线
# str4 = '#'
str4 = '￥'
print(re.match(pattern4,str4))
pattern5 = '[13567]'#注意要加引号，变成字符串
# str5 = '1'
str5 = '2'
print(re.match(pattern5,str5))
#匹配电话号码
pattern_1 = '\d\d\d\d\d\d\d\d\d\d\d'
str7 = '12345678906'
print(re.match(pattern_1,str7))
pattern_2 = '1[2356]\d\d\d\d\d\d\d\d\d'#对第一位和第二位进行指定数字匹配
str8 = '12345678906'
print(re.match(pattern_2,str8))
#限定符
pattern_2 = '\d*'#*匹配零次或者多次
# str_2 = '123abc'
str_2 = 'abc'#没有数字返回的不是None，是空，因为*可以匹配零次
print(re.match(pattern_2,str_2))
pattern_3 = '\d+'#+匹配1次或多次
# str_3 = '12abc'
str_3 = 'abc'#没有数字返回的是None,因为+匹配1次或多次
print(re.match(pattern_3,str_3))
pattern_4 = '\d?'#?匹配1次或者0次
str_4 = '123abc'
print(re.match(pattern_4,str_4))#可以匹配出第一个结果
pattern_5 = '\d{4}'#{m}重复m次
# str_5 = '12345avx'
str_5 = '123saaaaa'#数字小于m个会返回None，多余m个依然仍然是m
print(re.match(pattern_5,str_5))
pattern_6 = '\d{4,}'#{m,}至少重复m次
str_6 = '12354saaaaa'#数字小于m个会返回None，多余m个都可以匹配
# str_6 = '123saaaaa'
print(re.match(pattern_6,str_6))
pattern_7 = '\d{3,5}'#{m.n}重复3-5次即重复3-5个元素
# str_7 = '12354saaaaa'
# str_7 = '123547saaaaa'#多余5个仍然是5，因为最多是5
str_7 = '12saaaaa'#少于3个返回None
print(re.match(pattern_7,str_7))





